package com.example.demo.config.web;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

;

/**
 * 映射的配置类
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {


    /**
     * 支持跨域
     *
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        System.out.println("======支持跨域开启======");
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT","PATCH")
                .maxAge(3600);
    }

    /**
     * 这个方法是重写自愿定位的
     * 开放 upload 下面的所有资源。
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
       registry.addResourceHandler("/static/**").
               addResourceLocations("classpath:/static/");
        super.addResourceHandlers(registry);
    }

    /**
     * 这个方法是设置页面跳转的
     * @param registry
     */
//    @Override
//    public void addViewControllers(ViewControllerRegistry registry) {
//
//    }
}
